package leetcode;

import java.util.Stack;

/**
 * @program: data_structures_algorithms
 * @description: 反转字符串，不反转非字母
 * @author: lld
 * @create: 2020-11-18 19:57
 **/
public class Demo1 {
    public static void main(String[] args) {
        String s = "ab-cd*efg!";
        Stack<Character> stack = new Stack<>();
        for (Character c : s.toCharArray()) {
            if (Character.isLetter(c)) {
                stack.push(c);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (Character c : s.toCharArray()) {
            if (Character.isLetter(c)) {
                sb.append(stack.pop());
            } else {
                sb.append(c);
            }
        }
        System.out.println(sb);
    }
}
